const returnModel = require('../model/ReturnModel')
const { getTodoList,add,edit,del } = require('../conn/db')
const router = require('koa-router')()
//const { addToCache, getListInCache, editCache, delCache } = require('../cache/todolist')
let listData = []
router.get('/', async (ctx, next) => {
  await ctx.render('index', {
    title: 'Hello Koa 2!'
  })
})

router.get('/string', async (ctx, next) => {
  ctx.body = 'koa2 string'
})

router.post('/post', async (ctx, next) => {
  const data = ctx.request.body
  ctx.body = 'i am from post'
})

router.get('/json', async (ctx, next) => {

  const data = ctx.query


  returnModel.data = []
  returnModel.errno = 10002

  ctx.body =
  {
    "errno": 0,
    "data": [
      {
        "name": "John",
        "age": 17,
        "gender": "male"
      },
      {
        "name": "Tom",
        "age": 17,
        "gender": "male"
      },
      {
        "name": "Lucy",
        "age": 16,
        "gender": "female"
      }
    ]
  }
})


module.exports = router
